import { DrawType } from '@/utils/json2image.js';
export const getTicketJson = (dataInfo, json2image) => {
  let jsonData = [];
  if (!dataInfo) {
    return jsonData;
  }
  let bgItem = {
    type: DrawType.IMAGE,
    url: dataInfo.bgImgUrl,
    left: 0,
    top: 0,
    width: json2image.width,
    height: json2image.height
  };
  jsonData.push(bgItem);
  // 封面
  let coverItem = {
    type: DrawType.IMAGE,
    url: dataInfo.cover,
    left: 80,
    top: 228,
    width: 714,
    height: 357,
    radius: 24,
    objectFit: 'contain',
    filter: 40
  };
  jsonData.push(coverItem);
  //名称
  let titleTextItem = {
    type: DrawType.TEXT,
    content: dataInfo.name,
    fontSize: 36,
    lineHeight: 48,
    weight: 600,
    textAlign: 'left',
    color: '#333',
    left: 80,
    top: 615,
    maxWidth: 714,
    maxLine: 2,
    eplision:'...'
  };
  jsonData.push(titleTextItem);
  let titleTextHeight = json2image.getTextHeight(titleTextItem);
  console.log('--titleTextItem--', titleTextHeight);
  //活动时间
  let timeTextItem = {
    type: DrawType.TEXT,
    content: dataInfo.time,
    fontSize: 33,
    lineHeight: 36,
    textAlign: 'left',
    color: '#666',
    left: 80,
    top: 615 + titleTextHeight + 30
  };
  jsonData.push(timeTextItem);
  // 虚线分割
  let dashedLineItem = {
    type: DrawType.DASHED_LINE,
    color: '#e1e1e1',
    top: 615 + titleTextHeight + 30 + 36 + 43,
    left: 80,
    dashedWidth: 714,
    linewidth: 1
  };
  jsonData.push(dashedLineItem);
  // 票券名称
  let ticketNameTextItem = {
    type: DrawType.TEXT,
    content: `票券名称：${dataInfo.ticketName}`,
    fontSize: 33,
    textAlign: 'left',
    color: '#666',
    left: 80,
    top: 615 + titleTextHeight + 30 + 36 + 43 + 43,
    maxLine: 1,
    eplision:'...'
  };
  jsonData.push(ticketNameTextItem);
  // 票券价格前面文字
  let ticketPriceTextItem = {
    type: DrawType.TEXT,
    content: `票券价格：`,
    fontSize: 33,
    textAlign: 'left',
    color: '#666',
    left: 80,
    top: 615 + titleTextHeight + 30 + 36 + 43 + 43 + 42 + 18 + 10,
    maxLine: 1
  };
  jsonData.push(ticketPriceTextItem);
  //票券价格文字长度
  let ticketPriceTextWdith = json2image.getTextWidth(`票券价格：`, ticketPriceTextItem);
  // 票券人民币符号价格
  let ticketPriceSymbolWidth = 0;
  if (dataInfo.price != '免费') {
    let ticketPriceSymbolItem = {
      type: DrawType.TEXT,
      content: `¥`,
      fontSize: 33,
      fonweight: 600,
      textAlign: 'left',
      color: dataInfo.fontColor,
      left: 80 + ticketPriceTextWdith,
      top: 615 + titleTextHeight + 30 + 36 + 43 + 43 + 42 + 18 + 12
    };
    jsonData.push(ticketPriceSymbolItem);
    ticketPriceSymbolWidth = 20;
  }

  // 票券人民币价格
  let ticketPriceItem = {
    type: DrawType.TEXT,
    content: dataInfo.price,
    fontSize: 48,
    fonweight: 600,
    textAlign: 'left',
    color: dataInfo.fontColor,
    left: 80 + ticketPriceTextWdith + ticketPriceSymbolWidth,
    top: 615 + titleTextHeight + 30 + 36 + 43 + 43 + 42 + 18
  };
  jsonData.push(ticketPriceItem);

  //票券数量
  let ticketNumberTextItem = {
    type: DrawType.TEXT,
    content: `x${dataInfo.num}`,
    fontSize: 33,
    textAlign: 'right',
    color: '#666',
    left: 794,
    top: 615 + titleTextHeight + 30 + 36 + 43 + 43 + 42 + 18
  };
  jsonData.push(ticketNumberTextItem);

  // 二维码
  let qrCodeItem = {
    type: DrawType.IMAGE,
    url: dataInfo.qrcodeImg,
    left: 70,
    top: 1052,
    width: 166,
    height: 166
  };
  jsonData.push(qrCodeItem);

  return jsonData;
};
